package de.westranger.forex.trading.analysis;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Stack;

@Deprecated
public class ForexTimeSeriesReader {

	public static ForexTimeSeries read(final String path) {
		ForexTimeSeries result = null;
		try {
			BufferedReader bufRead = new BufferedReader(new FileReader(new File(path)));

			final Stack<Long> time = new Stack<Long>();
			final Stack<Double> low = new Stack<Double>();
			final Stack<Double> high = new Stack<Double>();

			while (bufRead.ready()) {
				String[] split = bufRead.readLine().split(";");

				time.push(Long.parseLong(split[0]));
				high.push(Double.parseDouble(split[1]));
				low.push(Double.parseDouble(split[2]));
			}

			bufRead.close();

			final long[] resultTime = new long[time.size()];
			final double[] resultLow = new double[time.size()];
			final double[] resultHigh = new double[time.size()];

			for (int i = 0; i < time.size(); i++) {
				resultTime[i] = time.elementAt(i);
				resultLow[i] = low.elementAt(i);
				resultHigh[i] = high.elementAt(i);
			}
			result = new ForexTimeSeries(resultTime, resultLow, resultHigh);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return result;
	}

}
